package org.example.sync.parkunpark;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

import java.util.concurrent.locks.LockSupport;

/**
 * @author zhengdp
 * @Description park 和 unPark 的基本使用
 * @Date 2022/10/16 22:51
 * @Created by zhengdp
 */
@Slf4j(topic = "c.ParkAndUnParkTest")
public class ParkAndUnParkTest {
    // park 时 线程处于 Wait方法
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            log.info("start ...");
            Sleeper.sleep(2000);
            log.info("park ....");
            LockSupport.park();
            log.info("resume ...");
        },"t1");
        t1.start();

        Sleeper.sleep(1000);
        log.info("unPark ...");
        LockSupport.unpark(t1);
    }


}
